//
//  ZYReportViewController.m
//  ZYOils
//
//  Created by 段新瑞 on 2019/9/24.
//  Copyright © 2019 Mr.Xr. All rights reserved.
//

#import "ZYReportViewController.h"

#import "ZYReportContentView.h"

#import "ZYCompanyDateModel.h"


@interface ZYReportViewController ()

@property(nonatomic, strong) UIScrollView *scrollView;
@property(nonatomic, strong) UIView *contentView;

/// 门店报表详细数据容器 View
@property(nonatomic, strong) ZYReportContentView *reportContentView;


@property (nonatomic, strong) ZYCompanyDateModel *companyDateModel;
@end

@implementation ZYReportViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"经营报表";
    [self customUI];
    [self configData];
}

- (void)customUI {
    [self.view addSubview:self.scrollView];
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.right.bottom.mas_equalTo(0);
    }];
    
    [self.scrollView addSubview:self.contentView];
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.scrollView);
        make.width.mas_equalTo(self.scrollView.mas_width);
        make.height.mas_equalTo(self.scrollView.mas_height).mas_equalTo(1);
    }];
    
    [self.contentView addSubview:self.reportContentView];
    [self.reportContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(7);
        make.right.mas_equalTo(-7);
        make.top.mas_equalTo(5);
        make.height.mas_equalTo(270);
    }];
}

- (void)configData {
    /// 获取账单最早日期
    [ZYHud showLoadingText:@""];
    [[DataManager manager] postGetCompanyDateParam:@{@"companyId": STR(ZYUserInfoModel.sharedInfoModel.userModel.companyId)} block:^(XRCommonModel *model, NSError *error) {
        // [ZYHud hideHud];
        if (model.isSuccess) {
            self.companyDateModel = [ZYCompanyDateModel mj_objectWithKeyValues:model.data];
            self.reportContentView.companyDateModel = self.companyDateModel;
        } else {
            if (![LBLimitInput isEmpty:model.error]) {
                [ZYHud showErrorText:model.error];
            }
        }
    }];
    
}

#pragma mark - 懒加载
- (UIScrollView *)scrollView {
    if (_scrollView == nil) {
        _scrollView = [UIScrollView new];
    }
    return _scrollView;
}

- (UIView *)contentView {
    if (_contentView == nil) {
        _contentView = [UIView new];
    }
    return _contentView;
}

- (ZYReportContentView *)reportContentView {
    if (_reportContentView == nil) {
        _reportContentView = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([ZYReportContentView class]) owner:nil options:nil] lastObject];
    }
    return _reportContentView;
}




- (ZYCompanyDateModel *)companyDateModel {
    if (!_companyDateModel) {
        _companyDateModel = [[ZYCompanyDateModel alloc] init];
    }
    return _companyDateModel;
}

@end
